package com.jackaltsc.mydemolist.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.Toast;


import com.jackaltsc.mydemolist.R;
import com.jackaltsc.mydemolist.adapter.ClassListAdapter;
import com.jackaltsc.mydemolist.entity.ClassEntity;
import com.jackaltsc.mydemolist.entity.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * ExpandableListView简单使用
 * <p>
 * Created by JackalTsc on 2016/7/13.
 */
public class ExListViewActivity extends Activity implements ExpandableListView.OnChildClickListener {

    private ExpandableListView mExListView;
    private List<ClassEntity> mData = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_activity_listex);

        initExListView();
    }

    private void initExListView() {

        getData();

        mExListView = (ExpandableListView) findViewById(R.id.elv_students);
        ExpandableListAdapter adapter = new ClassListAdapter(this, mData);
        mExListView.setAdapter(adapter);
        mExListView.setOnChildClickListener(this);
    }

    private void getData() {

        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student(R.mipmap.ic_launcher, "王小明"));
        stuList.add(new Student(R.mipmap.ic_launcher, "李小虎"));
        stuList.add(new Student(R.mipmap.ic_launcher, "赵大雷"));
        stuList.add(new Student(R.mipmap.ic_launcher, "刘小荣"));

        for (int i = 0; i < 6; i++) {
            mData.add(new ClassEntity("计科" + i + "班", stuList));
        }
    }

    @Override
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

        String text = mData.get(groupPosition).getStuList().get(childPosition).getStuName();

        Toast.makeText(this, text, Toast.LENGTH_SHORT).show();

        return true;

    }
}
